package smile.webservicemain.module;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;

import smile.entity.User;
import smile.webservicemain.service.Userservice;
import smile.webservicemain.service.impl.UserServiceImpl;
@At("/login")
@Ok("json")
@IocBean
public class LoginModule  {
	//这个注入也是，名字规则就是驼峰那种的。写错了就报注入失败
	//这里使用接口调用实体类的方法，这样方便代码阅读和修改，你试试看能不能运行
	@Inject
	private Userservice userServiceImpl =new UserServiceImpl();
	
	
	
	@At("/user-login")
	@POST
	public User userLogin(User user){
		try {
			if(userServiceImpl.login(user.getName(), user.getPassword()) == null){
				throw new RuntimeException("没有该用户 ...");
			}else {
				return userServiceImpl.login(user.getName(), user.getPassword());
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
